import os

# Command line arguments parsing
cppdefines = []
for key, value in ARGLIST:
    if key == 'define' and value == 'SEND':
        cppdefines.append(value)
    else :
        cppdefines.append('RECV');

env = Environment(CC = 'g++')
dbg = Environment(CC = 'g++', CCFLAGS = '-ggdb', CPPDEFINES = cppdefines)

env.Append(CPPPATH = ['../include/'])
env.ParseConfig('xml2-config --cflags --libs')
env.ParseConfig('pkg-config --cflags --libs libpjproject')

dbg.Append(CPPPATH = ['../include/', '/usr/local/include/'])
dbg.ParseConfig('xml2-config --cflags --libs')
dbg.ParseConfig('pkg-config --libs libpjproject')

sources = Split("""
    logger.c
    config.c
    net.c
    netfilter.c
    terminal.c
    utils.c
    databank.c
""")

dbg.Object(source = sources)

# Run build in subdirectories
path = "../main"
dir_list = ['rtp', 'sip']

for dir in dir_list:
    sconscript_path = os.path.join(path, dir)
    build_path      = os.path.join(dir)
    if ( not os.path.isdir(sconscript_path) ) :
        print "[!] Skipping " + sconscript_path + " [Not a directory]"
        continue
    if ( os.path.exists(sconscript_path) ) and ( os.path.isdir(sconscript_path) ) :
        print "Parsing " + sconscript_path
        SConscript( os.path.join(sconscript_path, 'SConscript'), variant_dir= build_path, duplicate = 0)
    else :
        print "Fail " + sconscript_path 
